package order

import (
	"context"
	"gitee.com/tietang/terrace-go/v2/base/plugin"
)

var _ CreateOrderServiceExt = new(CreateOrderServiceExtProxy)

type CreateOrderServiceExtProxy struct {
	plugin.PluginId
	exts        []CreateOrderServiceExt
	isInit      bool
	ExtExecutor plugin.PluginExecutor
}

//func (o *CreateOrderServiceExtProxy) Check(ctx context.Context, in interface{}) bool {
//	return true
//}

func (o *CreateOrderServiceExtProxy) PluginCode() string {
	return CreateOrderServicePluginId
}

func (o *CreateOrderServiceExtProxy) OnValidate(ctx context.Context, in *OrderDTO) error {
	return o.ExtExecutor.Execute(ctx, o.PluginCode(), in, func(s interface{}) error {
		err := s.(CreateOrderServiceExt).OnValidate(ctx, in)
		return err
	})
}

func (o *CreateOrderServiceExtProxy) Pre(ctx context.Context, in *OrderDTO) error {

	return o.ExtExecutor.Execute(ctx, o.PluginCode(), in, func(pluginInterface interface{}) error {
		err := pluginInterface.(CreateOrderServiceExt).Pre(ctx, in)
		return err
	})

}

func (o *CreateOrderServiceExtProxy) Post(ctx context.Context, in *OrderDTO, out *OrderDTO) error {

	return o.ExtExecutor.Execute(ctx, o.PluginCode(), in, func(pluginInterface interface{}) error {
		err := pluginInterface.(CreateOrderServiceExt).Post(ctx, in, out)
		return err
	})

}
